package com.orchidea.uml.view
{
import com.orchidea.uml.model.document.DocumentNode;
import com.orchidea.uml.view.presentation.DocumentPresentation;

import flash.events.Event;

import flash.utils.Dictionary;

import mx.core.Container;
import mx.core.UIComponent;

public class DiagramView extends UIComponent
{
    [Bindable]
    public var model:DocumentPresentation;

    /** A dictionary to keep track of which element is displayed in which view. */
    private var elementToView : Dictionary;

    protected function onCreationComplete():void
    {
        model.addEventListener("elementsChanged", handleModelChange);
    }

    /**
     * Handle structural changes in the model by adding or removing views.
     * The z-order of views corresponds to the order in the model's children.
     */
    private function handleModelChange(event:Event):void
    {
        for each(var e:DocumentNode in model.elements)
        {
            if (elementToView[e] == null)
            {
                // we got new element
                var view:Container = new DocumentElement();

                addChild(view);
                elementToView[e] = view;
            }
        }
    }
    
    /**
     * Handle property changes to the model by attempting some sort of incremental change
     * via updateModelProperty(), then falling back to reinitializing the view completely.
     */
    private function handleModelUpdate(e:Event):void
    {
        
    }



    private function createChildView():void
    {
        
    }
}
}